package com.example.properties1.confing;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:RabbitConfig
 * Package:com.example.ttl1.confing
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/11-21:21
 * @Version:v1.0
 */
@Configuration
public class RabbitConfig {

    @Value("${my.exchangeName}")
    private String exchangeName;

    @Value("${my.queueName}")
    private String queueName;

    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange(exchangeName).build();
    }

    @Bean
    public Queue queue() {
        /**
         * Queue(String name, boolean durable, boolean exclusive, boolean autoDelete,@Nullable Map<String, Object> arguments)
         * 参数一：队列名称
         * 参数二：持久化
         * 参数三：是否是排他队列
         * 参数四：自动删除
         * 参数五：参数 @Nullable Map<String, Object> arguments
         */

        Map<String, Object> arguments = new HashMap<>();

        //return new Queue(queueName,true,false,true);
        return new Queue(queueName,true,false,false);

    }

    @Bean
    public Binding binding(DirectExchange directExchange, Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with("info");
    }


}
